﻿using System.Management;
using System.Net.NetworkInformation;

namespace _64_C_读取计算机名称_硬盘型号_物理地址
{
    internal class Program
    {
        static void Main()
        {
            // 获取计算机名称
            string computerName = Environment.MachineName;
            Console.WriteLine("计算机名称: " + computerName);

            // 获取硬盘型号
            Console.WriteLine("硬盘型号:");
            GetDiskDriveInfo();

            // 获取网络适配器物理地址（MAC地址）
            Console.WriteLine("网络适配器物理地址 (MAC):");
            GetMACAddress();
        }

        // 获取硬盘型号
        static void GetDiskDriveInfo()
        {
            using (ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT Model FROM Win32_DiskDrive"))
            {
                foreach (ManagementObject disk in searcher.Get())
                {
                    Console.WriteLine("  " + disk["Model"]);
                }
            }
        }

        // 获取网络适配器物理地址（MAC地址）
        static void GetMACAddress()
        {
            foreach (NetworkInterface ni in NetworkInterface.GetAllNetworkInterfaces())
            {
                // 筛选出有效的网络接口（跳过回环或未启用的适配器）
                if (ni.NetworkInterfaceType != NetworkInterfaceType.Loopback && ni.OperationalStatus == OperationalStatus.Up)
                {
                    Console.WriteLine("  " + ni.GetPhysicalAddress().ToString());
                }
            }
        }
    }
}
